package com.gbb.common.simple;

import android.view.View;

/**
 * 防止频繁点击,多次执行点击事件 <br/>
 * 解释:每次点击事件执行之前 先判断俩次点击间隔是否大于500毫秒
 *
 * @author gaobingbing
 */
public abstract class OnClickEvent implements View.OnClickListener {

    private final static int MIN_INTERVAL = 500;

    private long lastTime;

    /**
     * 单击点击事件
     *
     * @param v View
     */
    abstract void singleClick(View v);

    @Override
    public void onClick(View v) {
        if(onDoubleClick()) {
            return;
        }
        singleClick(v);
    }

    private boolean onDoubleClick() {
        boolean flag = false;
        long time = System.currentTimeMillis() - lastTime;

        if(time < MIN_INTERVAL) {
            flag = true;
        }
        lastTime = System.currentTimeMillis();
        return flag;
    }
    
}
